﻿using KinonekoSoftware.ArkSpark.Core.Messages;
using KinonekoSoftware.ArkSpark.Documents;

namespace KinonekoSoftware.ArkSpark.Runtimes
{
    public abstract class DocumentElementPresenter : Spark, IArkSparkRuntimeModel
    {
        private bool _isEdit;

        public virtual DocumentElement GetDocumentElement() => null;

        public void Update()
        {
            //
            //
            Bus.OnNext(ElementUpdatedEventArgs.Instance);
        }

        public void ExternalProcess()
        {
            if (!UseExternalEditor)
            {
                return;
            }


            //
            //
            Bus.OnNext(ElementUpdatedEventArgs.Instance);
        }

        public         string Id                => GetDocumentElement().Id;
        public         bool   UseExternalEditor => GetDocumentElement().UseExternalEditor;
        public virtual bool   UseWYSIWYGEditor  => GetDocumentElement().UseWYSIWYGEditor;
        public virtual bool   IsSelectable      => true;

        public IArkSparkMQ Bus { get; set; }

        /// <summary>
        /// 获取或设置 <see cref="IsEdit"/> 属性。
        /// </summary>
        public bool IsEdit
        {
            get => _isEdit;
            set => SetValue(ref _isEdit, value);
        }
    }
}